package game.model.scene
{
	import flash.geom.Point;
	
	import game.define.NotificationNames;
	import game.model.scene.vo.MapConfigVO;
	import game.model.scene.vo.MapGridConfigVO;
	import game.model.scene.vo.SceneConfigVO;
	
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	import utiles.VOHelper;
	
	public class SceneProxy extends Proxy
	{
		public static const NAME:String = "SceneProxy";
		
		public function SceneProxy(proxyName:String=null, data:Object=null)
		{
			super(NAME, data);
		}
		
		private var _sceneConfigs:Object;
		private var _mapGridConfigs:Object;
		private var _mapConfigs:Object;
		
		public function setSceneConfig(value:Array):void
		{
			_sceneConfigs = {};
			
			var l:uint = value.length;
			for (var i:uint=0; i<l; i++)
			{
				var item:Object = value[i];
				var vo:SceneConfigVO = new SceneConfigVO();
				VOHelper.setVOData(item, vo);
				
				_sceneConfigs[vo.id] = vo;
				
				// perfect
				vo.mapConfigVO = _mapConfigs[vo.map];
			}
		}
		
		public function setSceneItemConfig(value:Object):void
		{
			
		}
		
		public function setMapConfig(value:Array):void
		{
			_mapConfigs = {};
			
			var l:uint = value.length;
			for (var i:int=0; i<l; i++)
			{
				var item:Object = value[i];
				var vo:MapConfigVO = new MapConfigVO();
				VOHelper.setVOData(item, vo);
				
				_mapConfigs[vo.id] = vo;
				
				// perfect
				vo.gridList = new Vector.<MapGridConfigVO>();
				var gridIds:Array = vo.grids.split(";");
				while (gridIds.length)
				{
					var gridId:int = gridIds.shift();
					var grid:MapGridConfigVO = _mapGridConfigs[gridId];
					vo.gridList.push(grid);
				}
			}
		}
		
		public function setMapGridConfig(value:Array):void
		{
			_mapGridConfigs = {};
			
			var l:uint = value.length;
			for (var i:int=0; i<l; i++)
			{
				var item:Object = value[i];
				var grid:MapGridConfigVO = new MapGridConfigVO();
				VOHelper.setVOData(item, grid);
				
				_mapGridConfigs[grid.id] = grid;
			}
		}
		
		///////////////////////////////////////////////////////////////////////////
		
		private var _currSceneID:int = 0;
		/**
		 * 服务器通知切换场景
		 * 
		 */		
		public function switchScene(sceneID:int, x:int, y:int):void
		{
			_currSceneID = sceneID;
			
			sendNotification(NotificationNames.SCENE_SWITCH, {sceneID:_currSceneID, x:x, y:y});
		}
		
		///////////////////////////////////////////////////////////////////////////
		
		public function getScene(sceneID:int):SceneConfigVO
		{
			return _sceneConfigs[sceneID];
		}
		
		public function getMap(mapID:int):MapConfigVO
		{
			return _mapConfigs[mapID];
		}
	}
}